require('dotenv').config();
const express = require('express');
const router = express.Router();
const httpUtil =  require('../util/httpUtil.js');
const fs = require("fs");
router.post('/init',function (req,res,next) {
  //url:'/portal/user/web/UserOrderQueryAction?action=initOrderQuery'
  var interUrl = '/portal/user/web/UserOrderForVueQueryAction?action=initOrderQueryVue';
  interUrl += ('&timePrior='+req.body.timePrior);
  httpUtil.doPost(interUrl,{},req.cookies).then(function(data){
    return res.json({
      orderInfos:JSON.parse(data),
    });
  }).catch(err=>{
    next(err);
    return {
    };
  });
 /* return res.json({
    orderInfos:fs.readFileSync('./data.json',"utf-8")
  })*/
});
router.post('/pay',function (req,res,next) {
  //校验用户是否登录,
  let interUrl = '/portal/pay/web/PaymentAction?action=skipPayPlatform';
  interUrl += ('&otherOrderId='+req.body.otherOrderId);
  interUrl += ('&payPaymentId='+req.body.payPaymentId);
  interUrl += ('&orderType='+req.body.orderType);
  interUrl += ('&clientOrMoblie='+req.body.clientOrMoblie);
  httpUtil.doPost(interUrl,{},req.cookies).then(function(data){
    return res.json(JSON.parse(JSON.parse(data)));
  }).catch(err=>{
    next(err);
    return {
    };
  });
});
module.exports = router;
